ColorButton: Don’t destroy dialog @ ::delete-event
authorHiroyuki Ito <ZXB01226@nifty.com>
Mon, 11 Sep 2017 12:02:13 +0000 (12:02 +0000)
committerDaniel Boles <dboles@src.gnome.org>
Tue, 12 Sep 2017 19:52:43 +0000 (20:52 +0100)
Without specifically connecting ::delete-event to something, the dialog
will be destroyed when it is closed, for example by pressing Esc. This
meant that when dismissing it this way, unlike by pressing Cancel, any
custom palette would be lost when the dialog was next opened, and so on.

Resolve this by making ::delete-event just do GTK_RESPONSE_CANCEL, so
closing the dialog has the same effect as clicking its Cancel button.

https://bugzilla.gnome.org/show_bug.cgi?id=787444

gtk/gtkcolorbutton.c

index b844d515fd841705a7c9b40870d8aa213e747837..e583cda0dd99ff63e5ded2cebb06cba3d6cca447 100644 (file)
@@ -489,6 +489,16 @@ gtk_color_button_new_with_rgba (const GdkRGBA *rgba)
   return g_object_new (GTK_TYPE_COLOR_BUTTON, "rgba", rgba, NULL);
 }
 
+static gboolean
+dialog_delete_event (GtkWidget *dialog,
+                     GdkEvent  *event,
+                     gpointer   user_data)
+{
+  g_signal_emit_by_name (dialog, "response", GTK_RESPONSE_CANCEL);
+
+  return TRUE;
+}
+
 static gboolean
 dialog_destroy (GtkWidget *widget,
                 gpointer   data)
@@ -554,6 +564,8 @@ ensure_dialog (GtkColorButton *button)
                     G_CALLBACK (dialog_response), button);
   g_signal_connect (dialog, "destroy",
                     G_CALLBACK (dialog_destroy), button);
+  g_signal_connect (dialog, "delete-event",
+                    G_CALLBACK (dialog_delete_event), button);
 }